package river_city_ransom.contracts;

import exceptions.ComposantError;
import exceptions.PostconditionError;
import exceptions.PreconditionError;
import river_city_ransom.decorators.Dimensions_D;
import river_city_ransom.services.Dimensions;


public class Dimensions_C extends Dimensions_D {
	public Dimensions_C(Dimensions delegate) {
		super(delegate);
	}
	
	@Override
	public String toString() {
		return super.toString();
	}
	
	/** _________________________________________________________ OBSERVATORS */
	@Override
	public int largeur() {
		return super.largeur();
	}

	@Override
	public int hauteur() {
		return super.hauteur();
	}

	@Override
	public int profondeur() {
		return super.profondeur();
	}

	/** ________________________________________________________ CONSTRUCTORS */
	@Override
	public void init(int l, int h, int p) throws ComposantError {
		boolean pre;
//		pre init(l, h, p) require l > 0 ^ h > 0 ^ p > 0
		pre = l > 0 && h > 0 && p > 0;
		if(!pre) {
			throw new PreconditionError("init(l, h, p) require l > 0 ^ h > 0 ^ p > 0");
		}
		
		super.init(l, h, p);
		
		boolean post;
//		post largeur(init(l, h, p)) = l
		post = largeur() == l;
		if(!post) {
			throw new PostconditionError("largeur(init(l, h, p)) = l");
		}
//		post hauteur(init(l, h, p)) = h
		post = hauteur() == h;
		if(!post) {
			throw new PostconditionError("hauteur(init(l, h, p)) = h");
		}
//		post profondeur(init(l, h, p)) = p
		post = profondeur() == p;
		if(!post) {
			throw new PostconditionError("profondeur(init(l, h, p)) = p");
		}
	}
}
